package org.neogenesis.web.controller;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.Query;

import org.neogenesis.web.dao.ExperimentDAO;
import org.neogenesis.web.dao.PlatformDAO;
import org.neogenesis.web.dao.SampleDAO;
import org.neogenesis.web.dao.SampleTypeDAO;
import org.neogenesis.web.model.Experiment;
import org.neogenesis.web.model.Platform;
import org.neogenesis.web.model.Sample;
import org.neogenesis.web.model.SampleType;

/**
 * @author Nancy
 * 
 */
@Named
@SessionScoped
public class SampleController implements Serializable {

	private Sample sample = new Sample();
	@Inject
	private SampleDAO sampleDAO;

	@Inject
	private SampleTypeDAO sampleTypeDAO;

	@Inject
	private PlatformDAO platformDAO;

	@Inject
	private ExperimentDAO experimentDAO;

	private List<Sample> selectedSamples = new ArrayList<Sample>();

	private FacesContext context = FacesContext.getCurrentInstance();

	private ResourceBundle bundle = context.getApplication().getResourceBundle(
			context, "bundle");

	public SampleController() {
		// TODO Auto-generated constructor stub

	}

	public void setSelectedSamples(List<Sample> selectedSamples) {
		this.selectedSamples = selectedSamples;
	}

	public List<Sample> getSelectedSamples() {
		return selectedSamples;
	}

	public void setSample(Sample sample) {
		this.sample = sample;
	}

	public Sample getSample() {
		return sample;
	}

	public List<Platform> getPlatformList() {
		List<Platform> platforms = platformDAO.findAll();
		return platforms;
	}

	public List<SampleType> getSampleTypes() {
		List<SampleType> types = sampleTypeDAO.findAll();
		return types;
	}

	public String create() throws IOException {
		sampleDAO.create(sample);

		return "";
	}

	public void deleteSample() {
		sampleDAO.removeSample(sample);
	}

	public List<Experiment> getExperimentList() {
		List<Experiment> experiments = experimentDAO.findAll();
		return experiments;
	}

}
